package com.fuqi.android.zhongcai.base.view.activity.deprecated;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.ActionSheetDialog;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.Constants;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGCommentActivity;
import com.fuqi.android.zhongcai.base.view.activity.ShowOrderImgAllActivity;
import com.fuqi.android.zhongcai.business.shuig.request.api.OrderDetailApi;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderDetailResult;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGCannotInstallActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGPaiGongActivity;
import com.fuqi.android.zhongcai.base.view.widget.TitleBar;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.android.zhongcai.utils.LogUtils;
import com.fuqi.framework.gson.GsonHelper;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;

import butterknife.Bind;
import butterknife.OnClick;
@Deprecated
public class OrderDetailSGDZActivity extends BaseActivity {


    @Bind(R.id.bottom_sgdz)
    LinearLayout bottomSgdz;
    @Bind(R.id.btn_no_contact)
    Button btnNoContact;
    @Bind(R.id.btn_sure_make_order)
    Button btnMakeOrder;
    @Bind(R.id.tv_order_status)
    TextView tvOrderStatus;
    @Bind(R.id.submit_time_summary)
    TextView submit_time_summary;

    @Bind(R.id.tv_origin)
    TextView tv_origin;
    @Bind(R.id.tv_time)
    TextView tv_time;
    @Bind(R.id.tv_no)
    TextView tv_no;
    @Bind(R.id.tv_contact_name)
    TextView tv_contact_name;
    @Bind(R.id.tv_contact_phone)
    TextView tv_contact_phone;
    @Bind(R.id.tv_install)
    TextView tv_install;
    @Bind(R.id.tv_install_date)
    TextView tv_install_date;
    @Bind(R.id.tv_install_address)
    TextView tv_install_address;
    @Bind(R.id.tv_huxing)
    TextView tv_huxing;
    @Bind(R.id.tv_ppr)
    TextView tv_ppr;
    @Bind(R.id.tv_pay_way)
    TextView tv_pay_way;
    @Bind(R.id.tv_remark)
    TextView tv_remark;
    @Bind(R.id.tv_check_time)
    TextView tv_check_time;
    @Bind(R.id.tv_inside)
    TextView tv_inside;
    @Bind(R.id.btn_call_inside)
    Button btn_call_inside;
    @Bind(R.id.team_leader)
    TextView team_leader;
    @Bind(R.id.btn_call_leader)
    Button btn_call_leader;
    @Bind(R.id.make_order_time)
    TextView make_order_time;
    @Bind(R.id.pre_mishu)
    TextView pre_mishu;
    @Bind(R.id.leader_remark)
    TextView leader_remark;
    @Bind(R.id.tv_worker)
    TextView tv_worker;
    @Bind(R.id.btn_call_worker)
    Button btn_call_worker;
    @Bind(R.id.tv_workers)
    TextView tv_workers;
    @Bind(R.id.chu_fa_time)
    TextView chu_fa_time;
    @Bind(R.id.no_shigong_reason)
    TextView no_shigong_reason;
    @Bind(R.id.next_install_date)
    TextView next_install_date;
    @Bind(R.id.tv_gr_remark)
    TextView tv_gr_remark;
    @Bind(R.id.no_install_img_1)
    ImageView no_install_img_1;
    @Bind(R.id.no_install_img_2)
    ImageView no_install_img_2;
    @Bind(R.id.no_install_img_3)
    ImageView no_install_img_3;
    @Bind(R.id.submit_time)
    TextView submit_time;
    @Bind(R.id.install_time)
    TextView install_time;
    @Bind(R.id.complete_time)
    TextView complete_time;
    @Bind(R.id.comment_time)
    TextView comment_time;
    @Bind(R.id.huifang_time)
    TextView huifang_time;
    @Bind(R.id.choucha_time)
    TextView choucha_time;
    @Bind(R.id.tv_jianli)
    TextView tv_jianli;

    @Bind(R.id.rl_chu_fa_time)
    RelativeLayout rlChuFaTime;
    @Bind(R.id.rl_no_shigong_reason)
    RelativeLayout rlNoShiGongReason;
    @Bind(R.id.rl_next_install_date)
    RelativeLayout rlNextInstallDate;
    @Bind(R.id.rl_tv_gr_remark)
    RelativeLayout rlTvGrRemark;
    @Bind(R.id.rl_no_install_img)
    RelativeLayout rlNoInstallImg;
    @Bind(R.id.rl_submit_time)
    RelativeLayout rlSubmitTime;
    @Bind(R.id.rl_install_time)
    RelativeLayout rlInstallTime;
    @Bind(R.id.rl_comment_time)
    RelativeLayout rlCommentTime;
    @Bind(R.id.rl_complete_time)
    RelativeLayout rlCompleteTime;
    @Bind(R.id.rl_tv_inside)
    RelativeLayout rlInside;
    @Bind(R.id.rl_huifang_time)
    RelativeLayout rl_huifang_time;
    @Bind(R.id.rl_choucha_time)
    RelativeLayout rl_choucha_time;
    @Bind(R.id.rl_jianli)
    RelativeLayout rl_jianli;
    @Bind(R.id.rl_team_leader)
    RelativeLayout rl_team_leader;
    @Bind(R.id.rl_make_order_time)
    RelativeLayout rl_make_order_time;
    @Bind(R.id.rl_pre_mishu)
    RelativeLayout rl_pre_mishu;
    @Bind(R.id.rl_leader_remark)
    RelativeLayout rl_leader_remark;
    @Bind(R.id.rl_tv_worker)
    RelativeLayout rl_tv_worker;




    @OnClick({R.id.btn_no_contact,R.id.btn_sure_make_order})
    public void onClick(View v){



            // 施工队长
            switch (v.getId()){

                case R.id.btn_no_contact:
                    ActivityUtils.startActivity(OrderDetailSGDZActivity.this,ShuiGCannotInstallActivity.class);
                    break;
                case R.id.btn_sure_make_order:
                    ActivityUtils.startActivity(OrderDetailSGDZActivity.this,ShuiGPaiGongActivity.class);
                    break;


            }


    }






    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };


    @Override
    public void initView() {

            // 施工队长
            bottomSgdz.setVisibility(View.VISIBLE);





    }


    private void addBottomSheet(final String addPerformFlag){

        titleBar.addAction(new TitleBar.ImageAction(R.mipmap.ic_more) {
            @Override
            public void performAction(View view) {

                    if (addPerformFlag.equals(Constants.YI_PING_LUN)){

                        showGRKHSelectSheet();
                    } else {

                        showSelectSheet();
                    }

            }
        });


    }

    private void showSelectSheet() {

        final String[] stringItems = {"查看订单图片"};
        final ActionSheetDialog dialog = new ActionSheetDialog(OrderDetailSGDZActivity.this, stringItems, null);
        dialog.isTitleShow(false).show();

        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                ActivityUtils.toast(stringItems[position]);
                dialog.dismiss();
                if (position == 0) {

                    ActivityUtils.startActivity(getApplicationContext(),ShowOrderImgAllActivity.class);
                }


            }
        });
    }


    private void showGRKHSelectSheet() {

        final String[] stringItems = {"查看评论", "查看订单图片"};
        final ActionSheetDialog dialog = new ActionSheetDialog(OrderDetailSGDZActivity.this, stringItems, null);
        dialog.isTitleShow(false).show();

        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                ActivityUtils.toast(stringItems[position]);
                dialog.dismiss();
                if (position == 0) {
                    Bundle bundle = new Bundle();
                    bundle.putString("order_id",getIntent().getStringExtra("order_id"));
                    LogUtils.i("order_id: " + getIntent().getStringExtra("order_id"));
                    ActivityUtils.startActivity(getApplicationContext(),ShuiGCommentActivity.class,bundle);
                } else if (position == 1){

                    ActivityUtils.startActivity(getApplicationContext(),ShowOrderImgAllActivity.class);
                }


            }
        });
    }


    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

        titleBar.setTitle("订单详情");
        LogUtils.i("order_id: " + getIntent().getStringExtra("order_id"));
        RequestManager.getInstance().call(new OrderDetailApi(new OrderDetailApi.OrderDetailParams(getIntent().getStringExtra("order_id")),
                respOrderDetailListener, errorListener));

    }

    Response.Listener<OrderDetailResult> respOrderDetailListener = new Response.Listener<OrderDetailResult>() {

        @Override
        public void onResponse(OrderDetailResult response) {

            if (HandleCode.requestSuccess()) {

                switch (Constants.KE_HU_NO_CONTACT){

                    case Constants.DAI_SHE_HE:
                        tvOrderStatus.setText("待审核");
                        break;
                    case Constants.BU_TONG_GUO:
                        tvOrderStatus.setText("不通过");
                        break;
                    case Constants.DAI_CHU_FA:
                        tvOrderStatus.setText("待出发");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        rlSubmitTime.setVisibility(View.GONE);
                        rlInstallTime.setVisibility(View.GONE);
                        rlCommentTime.setVisibility(View.GONE);
                        rlCompleteTime.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        break;
                    case Constants.DAI_AN_ZHUANG:
                        tvOrderStatus.setText("待安装");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        rlInside.setVisibility(View.GONE);
                        rlInstallTime.setVisibility(View.GONE);
                        rlCommentTime.setVisibility(View.GONE);
                        rlCompleteTime.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        break;
                    case Constants.DAI_CHU_LI_ORDER:
                        tvOrderStatus.setText("待处理");
                        break;
                    case Constants.AN_ZHUANG_ZHONG:
                        tvOrderStatus.setText("安装中");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        rlCommentTime.setVisibility(View.GONE);
                        rlCompleteTime.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        break;
                    case Constants.BU_KE_AN_ZHUANG:
                        tvOrderStatus.setText("不可安装");
                        submit_time_summary.setText("提交时间");
                        rlInstallTime.setVisibility(View.GONE);
                        rlCommentTime.setVisibility(View.GONE);
                        rlCompleteTime.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        break;
                    case Constants.AN_ZHUANG_WAN_CHENG:
                        tvOrderStatus.setText("已完成");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        rlCommentTime.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        break;
                    case Constants.DAI_HUI_FANG:
                        tvOrderStatus.setText("待回访");
                        break;
                    case Constants.YI_HUI_FANG:
                        tvOrderStatus.setText("已回访");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        rl_choucha_time.setVisibility(View.GONE);
                        rl_huifang_time.setVisibility(View.VISIBLE);
                        rl_choucha_time.setVisibility(View.GONE);
                        rl_jianli.setVisibility(View.GONE);
                        addBottomSheet(Constants.YI_HUI_FANG);
                        break;
                    case Constants.YI_CHOU_CHA_ORDER:
                        tvOrderStatus.setText("已抽查");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        rlInside.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);

                        rl_choucha_time.setVisibility(View.VISIBLE);
                        rl_huifang_time.setVisibility(View.VISIBLE);
                        rl_choucha_time.setVisibility(View.VISIBLE);
                        rl_jianli.setVisibility(View.VISIBLE);
                        addBottomSheet(Constants.YI_CHOU_CHA_ORDER);
                        break;
                    case Constants.YI_PING_LUN:
                        tvOrderStatus.setText("已评论");
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        rlInside.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.GONE);
                        addBottomSheet(Constants.YI_PING_LUN);
                        break;
                    case Constants.KE_HU_NO_CONTACT:
                        // 客户无法联系
                        tvOrderStatus.setText("待处理");
                        rlInstallTime.setVisibility(View.GONE);
                        rlCommentTime.setVisibility(View.GONE);
                        rlCompleteTime.setVisibility(View.GONE);
                        rlChuFaTime.setVisibility(View.GONE);
                        rlNoShiGongReason.setVisibility(View.GONE);
                        rlNextInstallDate.setVisibility(View.GONE);
                        rlTvGrRemark.setVisibility(View.GONE);
                        rlNoInstallImg.setVisibility(View.GONE);
                        bottomSgdz.setVisibility(View.VISIBLE);
                        rlChuFaTime.setVisibility(View.GONE);
                        rlSubmitTime.setVisibility(View.GONE);
                        rl_tv_worker.setVisibility(View.GONE);
                        rl_leader_remark.setVisibility(View.GONE);
                        rl_pre_mishu.setVisibility(View.GONE);
                        rl_make_order_time.setVisibility(View.GONE);
                        rl_team_leader.setVisibility(View.GONE);
                        break;


                }

                 setTextInfo(response);


                Log.i("juner", "juner OrderDetailResult response : " + GsonHelper.writeValue(response));
            } else {



            }
        }
    };

    private void setTextInfo(OrderDetailResult orderDetailResult) {


         tv_origin.setText(orderDetailResult.getOrderComefrom());
         tv_time.setText(orderDetailResult.getCreateDate());
         tv_no.setText(orderDetailResult.getOrderId());
         tv_contact_name.setText(orderDetailResult.getContactName());
         tv_install.setText(orderDetailResult.getInstallContent());
         tv_install_date.setText(orderDetailResult.getInstallDate());
         tv_install_address.setText(orderDetailResult.getAddArea());
         tv_huxing.setText(orderDetailResult.getHouseType());
         tv_ppr.setText(orderDetailResult.getProductType());
         tv_pay_way.setText(orderDetailResult.getPayType());
         tv_remark.setText(orderDetailResult.getRemark());
         tv_check_time.setText(orderDetailResult.getCHECK_DATE());
         tv_inside.setText(orderDetailResult.getInnerName());
         team_leader.setText(orderDetailResult.getCaptainName());
         make_order_time.setText(orderDetailResult.getDispatchDate());
         pre_mishu.setText(orderDetailResult.getUSE_METER());
         leader_remark.setText(orderDetailResult.getCaptainReamrk());
         tv_worker.setText(orderDetailResult.getChargehandName());

         tv_workers.setText(orderDetailResult.getWorkerNames());
         chu_fa_time.setText(orderDetailResult.getSetOutDate());
         no_shigong_reason.setText(orderDetailResult.getREFUSE_REASON());
         next_install_date.setText(orderDetailResult.getREFUSE_DATE());
         tv_gr_remark.setText(orderDetailResult.getWorkerNames());
//         no_install_img_1
//         no_install_img_2;
//         no_install_img_3;
         submit_time.setText(orderDetailResult.getSetOutDate());
         install_time.setText(orderDetailResult.getInstallDate());
         complete_time.setText(orderDetailResult.getCOMMENT_DATE());
         comment_time.setText(orderDetailResult.getCOMMENT_DATE());
         huifang_time.setText(orderDetailResult.getVISIT_DATE());
         choucha_time.setText(orderDetailResult.getCHECK_DATE());
         tv_jianli.setText(orderDetailResult.getCHECK_BY());
         btn_call_leader.setTag(orderDetailResult.getCaptainPhone());
         btn_call_worker.setTag(orderDetailResult.getChargehandPhone());
         btn_call_inside.setTag(orderDetailResult.getInnerPhone());
         btn_call_leader.setOnClickListener(listener);
         btn_call_worker.setOnClickListener(listener);
         btn_call_inside.setOnClickListener(listener);
    }



    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

             if (!v.getTag().toString().trim().equals(""))    {

                 ActivityUtils.callTo(OrderDetailSGDZActivity.this,v.getTag().toString().trim());

             }

        }
    };



    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_detail_sgdz;
    }
}
